package com.hkts.naturalgas.alarminformation.controller;

import com.hkts.naturalgas.alarminformation.entity.NaturalgasEquipment;
import com.hkts.naturalgas.alarminformation.entity.NaturalgasGateStation;
import com.hkts.naturalgas.alarminformation.service.INaturalgasEquipmentService;
import com.hkts.naturalgas.utils.TestDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassNameNaturalgasSiteDetailsController
 * @Description 站点详情
 * @Author yck
 * @Date2020-09-21 11:27
 * @Version V1.0
 **/
@RestController
@RequestMapping("/instrumentdata/siteDetails")
public class NaturalgasSiteDetailsController {

    @Autowired
    public INaturalgasEquipmentService iNaturalgasEquipmentService;

    @GetMapping("/getSiteDetails")
    @ResponseBody
    public List<Map<String, Object>> getSiteDetails(NaturalgasEquipment naturalgasEquipment) {
        List<NaturalgasEquipment> naturalgasEquipments = iNaturalgasEquipmentService.selectList(naturalgasEquipment);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        for (int i = 0; i < naturalgasEquipments.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("time", ss.format(new Date()));
            map.put("parameter", naturalgasEquipments.get(i).getEquipmentName());
            map.put("value",getEqumentParameterValue(naturalgasEquipments.get(i).getSiteArea()) );
            map.put("belongEquipment", naturalgasEquipments.get(i).getEquipmentName());
            list.add(map);
        }
        return list;
    }

    public Float getEqumentParameterValue(String siteArea) {
        float equmentValue=0;
         if(siteArea.equals("1")){
             equmentValue= TestDataUtils.getHoursData();
         }else if(siteArea.equals("2")){
             equmentValue=TestDataUtils.getHoursData();
         }else if(siteArea.equals("3")){
             equmentValue=TestDataUtils.getInstantaneousData();
         }else if(siteArea.equals("4")){
             equmentValue=TestDataUtils.getInstantaneousData();
         }else if(siteArea.equals("5")){
             equmentValue=TestDataUtils.getTemperatureData();
         }
        return equmentValue;
    }

}
